package com.pat.web.controller;

import java.io.IOException;
import java.io.InputStream;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;

import com.jfinal.core.Controller;
import com.jfinal.render.TemplateRender;

public class IndexController extends Controller{

	public void index(){
		render("hello.html");
	}
	
	public void errorcode(){
		InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("error_code.properties");
		byte[]data = new byte[4096];
		HttpServletResponse response = getResponse();
		response.setContentType("text/plain; charset=utf-8");
		try {
			ServletOutputStream sos = response.getOutputStream();
		
			int i;
			while((i = is.read(data))!=-1){
				sos.write(data,0,i);
			}
			is.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void api(){
		render(new TemplateRender("API.txt"){
			@Override
			public String getContentType() {
				return "text/plain; charset=utf-8";
			}
		});
		
	}
}
